﻿
var serializer = new JSONSerializer();

$(document).ready(function () {

    //待匹配理财收益ID
    var url = new Url();
    var $Id = url.GetQueryString("id");

    $.ajax({
        type: "post",
        url: '../Handler/FinaProfitHandler.ashx',
        dataType: "json",
        data: { Id: $Id, Type: 1, _: Math.random() },
        async: false,
        cache: false,
        complete: function () {
        },
        success: function (result) {
            if (result.Status) {
                serializer.DeSerializeToSpan($("#showResult"), result.Data);

                //预加载债权匹配信息列表
                $.ajax({
                    type: "post",
                    url: "../Handler/CreditProfitMatchHandler.ashx",
                    dataType: "json",
                    data: { FinaProfitId: $("div[data-name='FinaProfitId']").text(), type: 0, _: Math.random() },
                    async: true,
                    cache: false,
                    complete: function () {
                    },
                    success: function (result) {
                        if (result.Status) {
                            var $Total = 0;
                            $.each(result.Data, function (index, item) {
                                $Total += parseFloat(item.LoanMatchAmount);
                                $("#MatchCreditTemplete").tmpl(item).insertBefore($("#rowMatchAmountTotal"));
                            });
                            $("#totalMatchAmount").text($Total.toFixed(2));
                        }
                    }
                });


                //单独绑定理财规模*10000
                $("div[data-name='Amount']").text(result.Data.Amount * 10000);
                $("#animation").hide();
                $("#showResult").show();
            }
        }
    });
});